package com.kxn.multi.module.common.exception;

import com.kxn.multi.module.common.pojo.ResultCode;

/**
 * 通用业务异常
 *
 */
public class ServiceException extends RuntimeException {

    private ResultCode resultCode;

    private Object data;

    public ServiceException() {
        super();
        this.resultCode = ResultCode.FAIL;
    }

    public ServiceException(String message) {
        super(message);
        resultCode = ResultCode.FAIL;
        resultCode.setMsg(message);
    }

    public ServiceException(ResultCode resultCode) {
        super(resultCode.getMsg());
        this.resultCode = resultCode;
    }

    public ServiceException(ResultCode resultCode, String msg) {
        super(msg);
        this.resultCode = resultCode;
    }

    public ServiceException(ResultCode resultCode, Object data) {
        super(resultCode.getMsg());
        this.resultCode = resultCode;
        this.data = data;
    }

    public ServiceException(String message, Object... params) {

    }

    public static ServiceException getInstance(String message, Object... params) {
        message = String.format(message, params);
        return new ServiceException(message);

    }

    public ResultCode getResultCode() {
        return resultCode;
    }

    public Object getData() {
        return data;
    }
}
